import { ApiProperty } from '@midwayjs/swagger';
import { getSchema, Rule, RuleType } from '@midwayjs/validate';
import { alternatives, StrIdValidator } from '..';
import { ArticleCategorySchema, ArticleSchema } from '../../schema';

export class SaveArticleValidator implements ArticleSchema {
  @ApiProperty({
    type: 'string',
    title: '文章标题',
    example: 'null',
    description: '文章标题',
    required: true,
  })
  @Rule(RuleType.string().required())
  articleName: string;

  @ApiProperty({
    type: 'string',
    title: '文章副标题',
    example: 'null',
    description: '文章副标题',
    required: true,
  })
  @Rule(RuleType.string().required())
  articleSubName: string;

  @ApiProperty({
    type: 'string',
    title: '文章作者',
    example: 'null',
    description: '文章作者',
    required: true,
  })
  @Rule(RuleType.string().required())
  author: string;

  @ApiProperty({
    type: 'string',
    title: '文章摘要',
    example: 'null',
    description: '文章摘要',
    required: true,
  })
  @Rule(RuleType.string().required())
  intro: string;

  @ApiProperty({
    type: 'string',
    title: '文章内容',
    example: 'null',
    description: '文章内容',
    required: true,
  })
  @Rule(RuleType.string().required())
  context: string;

  @ApiProperty({
    type: 'boolean',
    title: '文章是否禁用',
    example: 'null',
    description: '文章是否禁用',
    required: true,
  })
  @Rule(RuleType.boolean().required())
  off: boolean;

  @ApiProperty({
    type: StrIdValidator,
    title: '文章分类',
    example: { id: '' },
    description: '文章分类',
    required: true,
  })
  @Rule(getSchema(StrIdValidator).required())
  category?: ArticleCategorySchema;
}

export class EditArticleValidator implements Partial<ArticleSchema> {
  @ApiProperty({
    type: 'string',
    title: '文章标题',
    example: 'null',
    description: '文章标题',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  articleName?: string;

  @ApiProperty({
    type: 'string',
    title: '文章副标题',
    example: 'null',
    description: '文章副标题',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  articleSubName?: string;

  @ApiProperty({
    type: 'string',
    title: '文章作者',
    example: 'null',
    description: '文章作者',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  author?: string;

  @ApiProperty({
    type: 'string',
    title: '文章摘要',
    example: 'null',
    description: '文章摘要',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  intro?: string;

  @ApiProperty({
    type: 'string',
    title: '文章内容',
    example: 'null',
    description: '文章内容',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  context?: string;

  @ApiProperty({
    type: 'boolean',
    title: '文章是否禁用',
    example: 'null',
    description: '文章是否禁用',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  off?: boolean;

  @ApiProperty({
    type: StrIdValidator,
    title: '文章分类',
    example: { id: '' },
    description: '文章分类',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  category?: ArticleCategorySchema;
}
